package ext.generic.part;

import com.ptc.netmarkets.util.beans.NmCommandBean;
import com.ptc.netmarkets.model.*;

import wt.fc.WTObject;

import wt.vc.Iterated;

import wt.method.RemoteAccess;
import wt.method.RemoteMethodServer;

import java.io.*;

import java.util.*;
/**
 * 获取"复制对象";
 */
public class GetPasteObjectData implements RemoteAccess, Serializable
{
    public GetPasteObjectData()
    {
    }

    public GetPasteObjectData newGetPasteObjectData()
    {
        GetPasteObjectData rc = new GetPasteObjectData();
        return rc;
    }

    /**
     * 获取用户复制的对象
     *
     * @param org   NmCommandBean
     * @return      Vector of user copy documents
     * @throws Exception
     */
    public static Vector GetClipboardContents(NmCommandBean nmcommandbean) throws Exception
    {
        if (!RemoteMethodServer.ServerFlag)
        {
            String method = "GetClipboardContents";
            String klass = GetPasteObjectData.class.getName();
            Class[] types =
            { NmCommandBean.class };
            Object[] vals =
            { nmcommandbean };
            return (Vector) RemoteMethodServer.getDefault().invoke(method, klass, null, types, vals);
        }

        Vector pasteObjects = new Vector();
        try
        {
            ArrayList arraylist = nmcommandbean.getClipped();
            int i = 0;
            if (arraylist != null && arraylist.size() > 0)
            {
                for (int j = 0; j < arraylist.size(); j++)
                {
                    Object obj = arraylist.get(j);
                    NmOid nmoid = null;
                    try
                    {
                        nmoid = NmCommandBean.getOidFromObject(obj);
                        WTObject wtobject = (WTObject) nmoid.getRef();
                        if (wtobject instanceof Iterated)
                        {
                            pasteObjects.add(wtobject);
                        }
                    }
                    catch (Exception e)
                    {
                        e.printStackTrace();
                    }
                }
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return pasteObjects;
    }
}
